from django.contrib import admin
from import_export import resources

from .models import Question, Choice, User

from import_export.admin import ImportExportModelAdmin

# Register your models here.

class ChoiceInline(admin.TabularInline):
    model = Choice
    extra = 3


# admin.site.register(Question)
@admin.register(Question)
class QuestionAdmin(ImportExportModelAdmin):
    list_display = ("id", "question_text", "pub_date",'was_published_recently')
    fieldsets = [
        (None,               {'fields': ['question_text']}),
        ('时间信息', {'fields': ['pub_date']}),
    ]
    inlines = [ChoiceInline]
    list_filter = ['pub_date']
    search_fields = ['question_text']
    ordering = ("id",)
    list_per_page = 15
    list_display_links = ("question_text",)


@admin.register(Choice)
class ChoiceAdmin(admin.ModelAdmin):
    list_display = ("id", "choice_text","votes","question_id")

    list_display_links = ("choice_text","question_id")

    list_per_page = 15

    ordering = ("id",)

@admin.register(User)
class UserAdmin(admin.ModelAdmin):
    list_display = ("uid","password")
    list_display_links = ("uid","password")
    list_per_page = 15


class QuestionResource(resources.ModelResource):

    class Meta:
        model = Question